package com.way.controller;

import com.way.common.core.domain.R;
import com.way.domain.dto.SysRoleDto;
import com.way.domain.entity.SysRole;
import com.way.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "角色管理")
@RequestMapping("role")
@RestController
public class SysRoleController {

    @Resource
    private SysRoleService service;

    @Operation(summary = "查找全部")
    @GetMapping("/")
    public R<List<SysRole>> findAll() {
        List<SysRole> data = service.findAll();
        return R.ok(data);
    }

    @Operation(summary = "按名称查找")
    @GetMapping("/{name}")
    public R<List<SysRole>> findByName(@Parameter(description = "角色名") @PathVariable("name") String name) {
        List<SysRole> data = service.findByName(name);
        return R.ok(data);
    }

    @Operation(summary = "保存")
    @PostMapping("/")
    public R<Void> save(@RequestBody SysRoleDto dto) {
        service.save(dto);
        return R.ok();
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    public R<Void> deleteById(@Parameter(description = "角色ID") @PathVariable("id") Integer id) {
        service.deleteById(id);
        return R.ok();
    }

}
